package com.xoa.controller.hr;

import com.xoa.model.hr.HrWorkExperience;
import com.xoa.model.hr.HrWorkExperienceWithBLOBs;
import com.xoa.service.hr.HrWorkExperienceService;
import com.xoa.util.CookiesUtil;
import com.xoa.util.ToJson;
import com.xoa.util.common.session.SessionUtils;
import com.xoa.util.dataSource.ContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("/hr/manage")
public class HrWorkExperienceController {

    @Resource
    HrWorkExperienceService hrWorkExperienceService;


    //主页面
    @RequestMapping("/staff_work_experience")
    public String bonpenManagement(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/HrWorkExperience/navigationBar";
    }
    //工作经历信息管理
    @RequestMapping("/bonpenManage")
    public String bonpenManage(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/HrWorkExperience/workExperienceManager";
    }
    //新建工作经历信息
    @RequestMapping("/bonpenNewedit")
    public String bonpenNewedit(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/HrWorkExperience/newWorkExperience";
    }
    //工作经历信息查询
    @RequestMapping("/bonpenQuery")
    public String bonpenQuery(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/HrWorkExperience/workExperienceQuery";
    }
    //工作经历信息导入
    @RequestMapping("/bonpenExport")
    public String bonpenExport(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/HrWorkExperience/workExperienceImport";
    }

    //工作经历信息详情页面
    @RequestMapping("/bonpenDetail")
    public String bonpenDetail(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/HrWorkExperience/workExperienceDetail";
    }



    //新建工作经历
    @ResponseBody
    @RequestMapping("/addHrWorkExperience")
    public ToJson<HrWorkExperienceWithBLOBs> addHrWorkExperience(HttpServletRequest request, HrWorkExperienceWithBLOBs hrWorkExperienceWithBLOBs){
        return hrWorkExperienceService.addHrWorkExperience(request,hrWorkExperienceWithBLOBs);
    }
    //更新奖惩信息
    @ResponseBody
    @RequestMapping("/updateHrWorkExperience")
    public ToJson<HrWorkExperienceWithBLOBs> updateHrWorkExperience(HttpServletRequest request,HrWorkExperienceWithBLOBs hrWorkExperienceWithBLOBs){
        return hrWorkExperienceService.updateHrWorkExperience(request,hrWorkExperienceWithBLOBs);
    }
    //删除&&批量删除
    @ResponseBody
    @RequestMapping("/deleteById")
    public ToJson<HrWorkExperience> deleteById(HttpServletRequest request,Integer wExperienceId[]){
        return hrWorkExperienceService.deleteById(request,wExperienceId);
    }
    //查询工作经历详情信息
    @ResponseBody
    @RequestMapping("/selectById")
    public ToJson<HrWorkExperience> selectById(HttpServletRequest request,Integer wExperienceId){
        return hrWorkExperienceService.selectById(request,wExperienceId);
    }
    //查询列表，导出
    @ResponseBody
    @RequestMapping(value = "/selectList")
    public ToJson<HrWorkExperienceWithBLOBs> selectList(HttpServletRequest request, HttpServletResponse response, HrWorkExperienceWithBLOBs hrWorkExperienceWithBLOBs, Integer page, Integer pageSize, boolean useFlag, String export){
        return hrWorkExperienceService.selectList(request,response,hrWorkExperienceWithBLOBs,page,pageSize,useFlag,export);
    }
    //导入
    @ResponseBody
    @RequestMapping(value = "/importWorkExperience", produces = {"application/json;charset=UTF-8"})
    public ToJson<HrWorkExperience> importWorkExperience(HttpServletRequest request, HttpServletResponse response, MultipartFile file) {
        return hrWorkExperienceService.importWorkExperience(request,response,file);
    }
}
